<?php

class Status_purchasing_order extends CI_Controller {
               
	function __construct()
	{
 		parent::__construct();
		$this->load->library('form_validation');
		$this->load->database();
		$this->load->helper('form');
		$this->load->helper('url');
		$this->load->model('pembelian/m_status_po');
	}	
	function index()
	{			
		$username 		= $this->session->userdata('username');
        $ilc['title']   = "Home &raquo Pembelian &raquo Status Surat Pesanan(Purchasing Order)";
			
		$this->form_validation->set_rules('no_po', 'No. Purchasing Order', 'required|max_length[10]');			
		$this->form_validation->set_rules('tgl_po', 'tgl_po', '');			
		$this->form_validation->set_rules('jns_pemasok', 'Jenis Pemasok', '');			
		$this->form_validation->set_rules('jns_pemasok2', 'Jenis Pemasok2', '');			
		$this->form_validation->set_rules('nm_supplier', 'Nama Supplier', 'required');			
		$this->form_validation->set_rules('alamat', 'Alamat', '');			
		$this->form_validation->set_rules('kota', 'Kota', '');			
		$this->form_validation->set_rules('kd_pos', 'Kode Pos', '');			
		$this->form_validation->set_rules('no_telp', 'No. Telp', 'is_numeric');			
		$this->form_validation->set_rules('no_fax', 'No. Fax', 'is_numeric');			
		$this->form_validation->set_rules('nm_cp', 'Contact Person', 'required');			
		$this->form_validation->set_rules('no_hp', 'No. Hp', 'is_numeric');			
		$this->form_validation->set_rules('email', 'Email', 'valid_email');			
		$this->form_validation->set_rules('web', 'Web', '');			
		$this->form_validation->set_rules('tgl_jatuh_pembayaran', 'Tgl Jatuh Pembayaran', 'required');			
		$this->form_validation->set_rules('status_produk_kena_ppn', 'Status Produk Kena PPn', '');			
		$this->form_validation->set_rules('status_produk_kena_ppn2', 'Status Produk Kena PPn2', '');			
		$this->form_validation->set_rules('total_po', 'Total Purchasing Order', '');			
		$this->form_validation->set_rules('netto', 'Netto', '');			
		$this->form_validation->set_rules('netto_ppn', 'Netto + PPn', '');			
		$this->form_validation->set_rules('diskon_rp', 'Diskon (Rp)', '');			
		$this->form_validation->set_rules('diskon_prsn', 'Diskon (%)', '');
			
		$this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');
	
		if ($this->form_validation->run() == FALSE) // validation hasn't been passed
		{
			$this->load->view('pembelian/v_status_po',$ilc);
		}
		else // passed validation proceed to post success logic
		{
		 	// build array for the model
			
			$form_data = array(
					       	'no_po' => set_value('no_po'),
					       	'tgl_po' => set_value('tgl_po'),
					       	'jns_pemasok' => set_value('jns_pemasok'),
					       	'jns_pemasok2' => set_value('jns_pemasok2'),
					       	'nm_supplier' => set_value('nm_supplier'),
					       	'alamat' => set_value('alamat'),
					       	'kota' => set_value('kota'),
					       	'kd_pos' => set_value('kd_pos'),
					       	'no_telp' => set_value('no_telp'),
					       	'no_fax' => set_value('no_fax'),
					       	'nm_cp' => set_value('nm_cp'),
					       	'no_hp' => set_value('no_hp'),
					       	'email' => set_value('email'),
					       	'web' => set_value('web'),
					       	'tgl_jatuh_pembayaran' => set_value('tgl_jatuh_pembayaran'),
					       	'status_produk_kena_ppn' => set_value('status_produk_kena_ppn'),
					       	'status_produk_kena_ppn2' => set_value('status_produk_kena_ppn2'),
					       	'total_po' => set_value('total_po'),
					       	'netto' => set_value('netto'),
					       	'netto_ppn' => set_value('netto_ppn'),
					       	'diskon_rp' => set_value('diskon_rp'),
					       	'diskon_prsn' => set_value('diskon_prsn')
						);
					
			// run insert model to write data to db
		
			if ($this->m_po->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db
			{
				redirect('pembelian/purchasing_order/success');   // or whatever logic needs to occur
			}
			else
			{
			echo 'Gagal Simpan Data Purchasing Order';
			// Or whatever error handling is necessary
			}
		}
	}
	function success()
	{
			echo 'Berhasil Simpan Data Purchasing Order';
	}
}
?>